<?php
include_once '../tools/common.php';
include_once '../tools/DbTools.php';
$is_login = getLoginStatus();
if(!$is_login){
    echo '尚未登入，<a href="../user/loginUi.php">请登入</a>';
    die;
}else{
    session_start();
    $usreInfo = $_SESSION[$_COOKIE['Token']];
    $realName = $usreInfo['realName'];
    $cardNum = $usreInfo['cardNum'];
    DbTools::InitDb();
    $sql = "select * from bankcard where CardState=0 and AccountId = ".$usreInfo['AccountId'].' and CardId!='.$usreInfo['CardId'];
    $result = DbTools::select($sql);
    //关闭连接
    DbTools::close();
}
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>卡列表</title>
</head>
<body>
    <form action="removeOtherCards.php" method="post">
        <table border="1" cellspacing="0" cellpadding="10px">
            <tr>
                <th><input type="checkbox" onclick="checkAll(event);"></th>
                <th>序号</th>
                <th>卡号</th>
                <th>余额</th>
            </tr>
            <?php
                foreach ($result as $key => $item){
            ?>
            <tr>
                <td><input type="checkbox" name="cardCheck[]" value="<?php echo $item['CardId'];?>"></td>
                <td><?php echo $key+1;?></td>
                <td><?php echo $item['CardNo'];?></td>
                <td><?php echo $item['CardMoney'];?></td>
            </tr>
             <?php
                }
             ?>
        </table>
        <button type="submit" >销卡</button>
    </form>
</body>
    <script>
        function checkAll(event) {
            var checkStatus = event.target.checked;
            var allCards = document.getElementsByName('cardCheck[]');
            for(var i=0;i<allCards.length;i++){
                allCards[i].checked = checkStatus;
            }
        }
    </script>
</html>
